import React,{Component} from 'react';
import {Icon} from 'antd';
import axios from 'axios';
import './index.scss';
class Details extends Component{

    constructor(){
        super();
        this.state = {
            itemObj:{},
			item_id:'',
			app_price:0,
			market_price:0,
			success:false,//表示是否添加成功
            total:0,//总数量
            item_uid:'',//对应的长图id
            item_xq:[]//详情长图
        }
    }

    backFunc=()=>{
        this.props.history.go(-1);
        // console.log(this.props.match.params.item_id)
        // console.log(this.props.location.search);
        //item.over_image_url   item.item_id   item.max_price
    }
    componentDidMount(){
        // console.log(this.props.location.search);
        let item_id = new URLSearchParams(this.props.location.search).get('item_id');
        this.setState({
           item_id: item_id,
           app_price: new URLSearchParams(this.props.location.search).get('app_price'),
           market_price: new URLSearchParams(this.props.location.search).get('market_price')
       })
       axios.get('item/reviews/list?item_id='+item_id+'&count=1&offset=0').then((res)=>{
            console.log(res);
            if(JSON.stringify(res.data.data) === "{}"){
                    console.log('res为空');
            }else{
                this.setState({                                              
                    itemObj:res.data.data.reviews[0],
                    item_uid:res.data.data.reviews[0].item_uid              
                })
            }
            
            let item_uid = this.state.item_uid;
                console.log(item_uid)
                axios.get('item/desc/data/get?item_uid='+item_uid).then((resp)=>{
                    // item/desc/data/get?item_uid=11_25533
                    // item/desc/data/get?item_uid=11_25533
                // console.log(resp);
                // console.log(item_uid);
                    this.setState({
                        item_xq:resp.data
                    
                    })
                })  
                axios.get('/item/desc/data/get?item_uid=11_25533').then((resp)=>{
                    console.log(resp);
                })          

       })
    //     setTimeout(()=>{
    //     let item_uid = this.state.item_uid;
    //     axios.get('item/desc/data/get?item_uid='+item_uid).then((resp)=>{
    //          console.log(resp);
    //          console.log(item_uid);
    //          this.setState({
    //              // item_xq:resp
               
    //          })
    //     })
    //    },2000)
       
    }
    render(){
        let itemObj = this.state.itemObj;
        let item_xq = this.state.item_xq;
        return (
            <div id='Details'>
                <div className='Details_title'><div className="div1" onClick={this.backFunc}><Icon type="left" className="leftBack" /></div><div className="div2">详情页</div></div>
                <div className='Details_content'>
                    <div className='Details_div1'>
                        <img src={itemObj.sku_img_url} alt={itemObj.sku_name}/>
                    </div>
                    <div className='Details_div2'>
                        <ul>
                            {
                                item_xq.map((item,key)=><li key={key}>
                                    <img src={item} alt='ddd'/>
                                </li>)
                            }
                        </ul>
                    </div>
                </div>
                <div className='Details_foot'>
                    <div className='foot_1'>加入购物车</div>
                    <div className='foot_2'>立即购买</div>
                </div>
            </div>
        )
    }
}
export default Details;